package com.food.restaurantpro.activity;

import com.food.restaurantpro.R;
import com.food.restaurantpro.imageloader.FileCache;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Html;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class FoodDetailActivity extends Activity {
	
	public static String KEY_FOOD_URL_IMAGE = "food_image";
	public static String KEY_FOOD_DESCRIPTION = "food_description";
	public static String KEY_FOOD_PRICE = "food_price";
	
	private FoodDetailActivity _me = this;
	private ImageView imageview;
	private TextView tvDescription;
	private TextView tvPrice;
	
	private FileCache mFileCache;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		_me.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		//Trong file AndroidManifest.xml set Theme.Dialog
		//Dong nay dung set transparent cho dialog
		_me.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
		setContentView(R.layout.activity_food_detail);
		mFileCache = new FileCache(_me);
		
		imageview = (ImageView) _me.findViewById(R.id.imageview_fooddetail);
		tvDescription = (TextView) _me.findViewById(R.id.tvDescription);
		tvPrice = (TextView) _me.findViewById(R.id.tvPrice);
		
		Bundle bundle = getIntent().getExtras();
		String url = bundle.getString(KEY_FOOD_URL_IMAGE);
		String des = bundle.getString(KEY_FOOD_DESCRIPTION);
		String price = bundle.getString(KEY_FOOD_PRICE);
		
		if(url == null) {
			url = "";
		}
		imageview.setImageBitmap(mFileCache.getBitmapByUrl(url));
		tvDescription.setText(Html.fromHtml("<b><font color=#c73737>Description: </font></b><font color=#2E2A2A>" + des + "</font>"));
		tvPrice.setText(Html.fromHtml("<b><font color=#c73737>Price: </font></b><font color=#2E2A2A>$" + price + "</font>"));
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		_me.finish();
		return super.onTouchEvent(event);
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		imageview.setImageBitmap(null);
		imageview = null;
		mFileCache = null;
	}
}
